package xyz.bali16.module.netdisk.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.bali16.module.netdisk.entity.FileFolder;
import xyz.bali16.module.netdisk.mapper.FileFolderMapper;
import xyz.bali16.module.netdisk.model.filefolder.FileFolderAddParam;
import xyz.bali16.module.netdisk.model.filefolder.FileFolderPageParam;
import xyz.bali16.module.netdisk.model.filefolder.FileFolderUpdateParam;
import xyz.bali16.module.netdisk.service.FileFolderService;


import java.util.List;


@Service("fileFolderService")
public class FileFolderServiceImpl extends ServiceImpl<FileFolderMapper, FileFolder> implements FileFolderService {

//    @Override
//    public List<UploadFile> getFilesByFileFolderId(String fileFolderId) {
//        return baseMapper.getFilesByFileFolderId(fileFolderId);
//    }


    @Override
    public List<FileFolder> getFileFoldersByParentFolderId(String parentFolderId) {
        return baseMapper.getFileFoldersByParentFolderId(parentFolderId);
    }


    @Override
    public List<FileFolder> getRootFoldersByFileStorageId(String fileStorageId) {
    return baseMapper.getRootFoldersByFileStorageId(fileStorageId);
    }
    @Override
    public IPage<FileFolder> getPage(FileFolderPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getPage(page, param.getId(),param.getName(),param.getParentFolderId(),param.getFileStorageId());
    }

    @Override
    public void add(FileFolderAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "FileFolderAddParam 参数不能为为空");
        FileFolder fileFolder = new FileFolder();
        BeanUtils.copyProperties(param, fileFolder);
        System.out.println(fileFolder);
        save(fileFolder);
    }

    @Override
    public void update(FileFolderUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "FileFolderUpdateParam 参数不能为为空");
        FileFolder fileFolder = new FileFolder();
        BeanUtils.copyProperties(param, fileFolder);
        updateById(fileFolder);
    }

    @Override
    public void delete(String fileFolderId) throws Exception {
        if (fileFolderId == null) {
            return;
        }
        removeById(fileFolderId);
    }
}
